package com.zt.java.proxy;

public abstract class AbstractInterceptorHander {

    private AbstractInterceptorHander nextHandLer;

    public AbstractInterceptorHander() {
    }

    public AbstractInterceptorHander(AbstractInterceptorHander nextHandLer) {
        this.nextHandLer = nextHandLer;
    }

    public Object intercept(Invocation invocation){
        Object obj = null;
        doBefore();
        if(nextHandLer != null){
            obj =  nextHandLer.intercept(invocation);
        }else{
            try{
                obj =  invocation.getMethod().invoke(invocation.getTarget(),invocation.getArgs());
            }catch(Exception e){

            }
        }
        doAfter();
        return obj;
    }

    public abstract void doBefore();

    public abstract void doAfter();


    public AbstractInterceptorHander getNextHandLer() {
        return nextHandLer;
    }
    public void setNextHandLer(AbstractInterceptorHander nextHandLer) {
        this.nextHandLer = nextHandLer;
    }


}
